﻿@model Jb.Web.ViewModels.UtilityModels.ListConfig
@using Jb.Web.Utility;
@using Jb.Common.Extensions;

@{
    String pageTitle = "Resume List";
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = JobSeekerMenu.Resume;
    String urlFormat = Url.JobSeekerUrl("edit", "resume") + "/{0}";
    String resumeDownloadFormat = AppConstants.Directories.RESUMES + "/" + SessionCache.CurrentUser.JobSeekerID + "/{0}";
    if(Model.Pager != null){
        Model.Pager.UrlFormat = Url.JobSeekerUrl("List", "Resume") + "/{0}";
    }
    bool _CanPostResume = true;
    if (!UserInfo.IsJobSeeker || !SessionCache.CurrentUser.JobSeekerInfo.HasProfileCompleted){
        _CanPostResume = false;
    }        
}

<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>
        Add, Edit and manage your Resumes.
    </div>
</div>

@*@{String autoClass = Model == null || Model.DataSource.Rows.Count <= 0 ? String.Empty : "auto";}*@
<div class="jb-page-content auto">
    @if (_CanPostResume) {
    <a href="@Url.JobSeekerUrl("Edit", "Resume")">Add New Resume</a>
    }
    else {
        @Html.WarningMessageBox("Please complete your job seeker profile first to upload your resume. <br/><br/><a href='/JobSeeker/Home/ProfileEdit' class='btn'><i class='icon-user'></i> Click here</a> to complete your profile.")
    }
    <div id="divMessage"></div>
</div>

@Html.Partial("_ResumeList", Model.DataSource) 
@if (Model.Pager != null)
{
    String autoClass = Model.Pager.TotalRecord > 0 ? "auto" : String.Empty;
    <div class="jb-page-content @(autoClass)"> 
    @Html.Partial("_Pager", Model.Pager)
    </div>
}


<!--Modal Popup Section Start-->
<div id="divConfirmDialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="divPhotoEditModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
        <h4 id="myModalLabel">Confirm Delete</h4>
    </div>
    <div class="modal-body jb-inline-label">            
        <div id="divModalMesssage">Are sure you want to delete this resume?</div>
    </div>
    <div class="modal-footer">               
        <button type="button" class="btn btn-primary" onclick="DeleteResume();"><i class="icon-remove icon-white"></i> Delete</button>
        <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i> Cancel</button>
    </div>
</div>
<!-- Modal Popup Section End -->

@section PageHeadSection{
    <style type="text/css">
        .jb-job{padding: 0px 0px 10px 0px; }
        .jb-js-photo{max-width:130px;}
        .jb-left-padding{padding-left:20px;}
        .jb-right-padding{padding-right:20px;}        
    </style>
}
@section JavaScriptPlaceHolder{
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            $('.delete-resume').each(function () {
                $(this).click(function () {
                    ConfirmDelete($(this), $(this).attr('delete-resume-id'));
                });
            });            
        });
        var _DeleteAnchor = null;
        function ConfirmDelete(element, resumeID) {
            _DeleteAnchor = element;
            $('#divConfirmDialog').modal({ show: true });
        }
        function DeleteResume() {
            $('#divConfirmDialog').modal('hide');
            ShowLoadingAnimation(false);
            Ajax('@Url.JobSeekerUrl("DeleteResume", "Resume")', 'resumeID=' + $(_DeleteAnchor).attr('delete-resume-id')
                , function (result) {
                    HideLoadingAnimation();
                    var status = (parseInt(result));
                    if (status > 0) {
                        $(_DeleteAnchor).parent().parent().parent().slideUp('slow');
                        IncreaseResumeCount(-1);
                    }
                    $('#divMessage').html(BuildDeleteMessage(status));
                });
        }

        function ForceDelete(resumeID) {
            ShowLoadingAnimation(false);
            Ajax('@Url.JobSeekerUrl("DeleteResume", "Resume")', 'resumeID=' + resumeID + '&forceDelete=True', function (result) {
                HideLoadingAnimation();
                $('#divMessage').html(BuildDeleteMessage(parseInt(result)));
                $(_DeleteAnchor).parent().parent().parent().slideUp('slow');
                IncreaseResumeCount(-1);
            }); 
        }
        function BuildDeleteMessage(result){
            var html = result > 0 ? '<div class="alert alert-success">' : '<div class="alert alert-block">';
            html += '<button type="button" class="close" data-dismiss="alert">&times;</button>';
            if (result > 0)
                html += '<h4>Success!</h4> Resume Deleted Successfully';
            else if (result == -1)
                html += '<h4>Warning!</h4> Could not found resume for delete';
            else if (result == -2)
                html += '<h4>Warning!</h4> You have applied for a job with this resume, Are you sure you want to delete this? <a href="#" onclick="ForceDelete(' + $(_DeleteAnchor).attr('delete-resume-id') + ')" class="btn btn-mini">Force Delete Resume</a>';
            else if(result == -3)
                html += '<h4>Warning!</h4> Employer(s) choosen this resume for further consideration, Are you sure you want to delete this? <a href="#" onclick="ForceDelete(' + $(_DeleteAnchor).attr('delete-resume-id') + ')" class="btn btn-mini">Force Delete Resume</a>';
            else
                html += '<h4>Warning!</h4> You are not allowed to delete this resume.';
            html += '</div>';

            return html;
        }
        function IncreaseResumeCount(count){
            $('#spanResumeCount').html(parseInt($('#spanResumeCount').html()) + count);
        }
    </script>
}